package cn.jingyinghui.config;

import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class ArkConfig {

    private static final String MODEL_NAME = "doubao-1-5-pro-32k-250115";

    @Bean
    public ArkService arkService() {
        String apiKey = System.getenv("ARK_API_KEY");
        if (apiKey == null || apiKey.isEmpty()) {
            throw new IllegalStateException("ARK_API_KEY environment variable is not set.");
        }

        // 创建更大的连接池和调度器
        ConnectionPool connectionPool = new ConnectionPool(10, 5, TimeUnit.MINUTES);
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setMaxRequests(64);
        dispatcher.setMaxRequestsPerHost(10);

        return ArkService.builder()
                .dispatcher(dispatcher)
                .connectionPool(connectionPool)
                .apiKey(apiKey)
                .build();
    }

    public static String getModelName() {
        return MODEL_NAME;
    }
}
